import threading
import os
import time
from typing import Optional, Callable, Any, Iterable, Mapping


def task_01(range_count):

    for val in range(range_count):
        print(f'我是:{threading.current_thread().name},我的pid:{os.getpid()},父级pid:{os.getppid()},循环次数{val}')
        time.sleep(0.5)


def task_02(range_count):

    for val in range(range_count):
        print(f'我是:{threading.current_thread().name},我的pid:{os.getpid()},父级pid:{os.getppid()},循环次数{val}')
        time.sleep(1)

# 自己实现线程
class MyThread(threading.Thread):

    def __init__(self, count) -> None:
        # 初始化父类
        threading.Thread.__init__(self)
        self.count = count

    def run(self) -> None:
       #  调用其他方法
       task_01(self.count)


if __name__ == '__main__':
    t1 = threading.Thread(name="myThread_01",target=task_01,args=(5,))
    t2 = threading.Thread(name="myThread_02",target=task_02,args=(5,))
    # print("start before t1:",t1)
    # print("start before t2:",t2)
    # t1.start()
    # # t1.join()
    # t2.start()
    # time.sleep(5)
    # print("start end t1:", t1)
    # print("start end t2:", t2)
    my_thread = MyThread(count=5)
    my_thread.name = 'my_thread'
    my_thread.start()
